package com.swh;

import com.alibaba.druid.support.http.StatViewServlet;
import com.swh.config.ContextConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/10 16:47
 * @Version: 1.0
 */
public class start implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(ContextConfig.class);

        DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
        ServletRegistration.Dynamic registration = servletContext.addServlet("guguanjia", dispatcherServlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("/");

        StatViewServlet viewServlet = new StatViewServlet();
        ServletRegistration.Dynamic druidStatView = servletContext.addServlet("DruidStatView", viewServlet);
        druidStatView.addMapping("/druid/*");

        DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
        FilterRegistration.Dynamic filter = servletContext.addFilter("shiroFilter", filterProxy);
        filter.setInitParameter("targetFilterLifecycle", "true");
        filter.addMappingForUrlPatterns(null,true,"/*");


    }
}
